package classes_metier;

import java.util.HashMap;
import java.util.Iterator;

public class Magasin {
	private int id;
	private String adresse;
	private HashMap<String, PC> stock;
	
	public Magasin(int i, String a){
		this.id = i;
		this.adresse = a;
		stock = new HashMap<String, PC>();
	}

	public int getId() { return id;	}

	public void setId(int id) {	this.id = id;}

	public String getAdresse() { return adresse; }

	public void setAdresse(String adresse) { this.adresse = adresse; }

	public HashMap<String, PC> getStock() {
		return stock;
	}
	
	public boolean stocker(PC p){
		if(stock.containsKey(p.getNumSerie())){
			System.out.println("Ce PC est deja dans le stock!");
			return false;
		}
		p.setMag(this);
		stock.put(p.getNumSerie(), p);
		return true;
	}
	
	public PC destocker(String num){
        PC res;
        if(stock.containsKey(num)){
            res = stock.get(num);
            stock.get(num).setMag(null);
            stock.remove(stock.get(num));  
            return res;
        }
        return null;
	}
	
	public void afficherStock(){
		Iterator<String> it = stock.keySet().iterator();
		while(it.hasNext()){
			String cle = it.next();
			System.out.println(stock.get(cle).getNumSerie()+" "+stock.get(cle).getMarque());
		}
		System.out.println("Total: "+stock.size());
	}
}
